package com.jn.algorithm.day001.question1;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 江南大学1033190417
 * @date 2022/4/15 10:03
 */
public class Solution2 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i]))
                return new int[]{i, map.get(target - nums[i])};
            else {
                map.put(nums[i], i);
            }
        }
        return new int[0];
    }

    public static void main(String[] args) {
        Solution2 solution = new Solution2();
        int[] nums = new int[]{3, 2, 4};
        int[] ints = solution.twoSum(nums, 6);
        System.out.println(Arrays.toString(ints));
    }
}
